package com.example.fw;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class HelperWithWebDriverBase extends HelperBase{

	private WebDriver driver;

	public HelperWithWebDriverBase(ApplicationManager manager) {
		super(manager);
		driver = manager.getWebDriverHelper().getDriver();
	}

	protected void fillField(By locator, String name) {
		driver.findElement(locator).clear();
		driver.findElement(locator).sendKeys(name);
	}

	protected WebElement findElement(By name) {
		try {
			return driver.findElement(name);
		} catch (Exception e) {
			return null;
		}
	}
	
	protected List<WebElement> findElements(By name) {
		return driver.findElements(name);
	}

	protected void openAbsoluteUrl(String url) {
		driver.get(url);
	}
	
	protected void openUrl(String url) {
		driver.get(manager.getProperty("baseUrl") + url);
	}

	protected void click(By name) {
		findElement(name).click();
	}
	
	protected void clickLink(String link) {
		driver.findElement(By.linkText(link)).click();
	}
}
